package com.fs.cv.controller;

import com.fs.cv.pojo.pojodao.*;
import com.fs.cv.pojo.pojodao.Class;
import com.fs.cv.pojo.pojoview.AbsenceCourse;
import com.fs.cv.pojo.pojoview.CourseInfo;
import com.fs.cv.pojo.pojoview.StudentInfo;
import com.fs.cv.service.CourseService;
import com.github.pagehelper.PageInfo;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.session.Session;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 课程管理的web层。
 */
@Controller
@RequestMapping("/course")
public class CourseController {

    @Autowired
    private CourseService courseService;

    @RequestMapping("queryAll")
    @ResponseBody
    public Map<String,Object> queryAll(){
        List<Course> courses = courseService.queryAll();
//        System.out.println(courses  +"========================");

        Map<String,Object> result = new HashMap<>();
        result.put("code",0);
        result.put("message","获取用户数据成功");
        result.put("courseList",courses);
        return result;
    }
    @RequestMapping("queryAllCourseDepartment")
    @ResponseBody
    public Map<String,Object> queryAllCourseDepartment(){
        List<CourseInfo> courses =  courseService.queryAllCourseDepartment();

        Map<String, Object> result = new HashMap<>();
        result.put("code",0);
        result.put("message","获取用户数据成功");
        result.put("courseList",courses);
        return result;
    }

    //添加课程专业信息
    @RequestMapping("addCourseDepartment")
    @ResponseBody
    public Map<String, Object> addCourseDepartment(CourseInfo courseInfo){
//        System.out.println(courseInfo);
        courseService.addCourseDepartment(courseInfo);

        Map<String, Object> result = new HashMap<>();
        result.put("code",0);
        result.put("message","添加课程信息成功");
        return result;
    }

    //根据课程表的编号删除一门课表
    @RequestMapping("deleteOneCourse")
    @ResponseBody
    public Map<String,Object> deleteOneCourse(Integer courseId){
       Map<String,Object> result = new HashMap<>();
        int i = courseService.deleteOneCourse(courseId);
//        System.out.println("i = " + i);
        if (i>0){
            result.put("code",0);
            result.put("message","删除课程表成功");
        }else {
            result.put("code",-1);
            result.put("message","删除课程表失败");
        }
        return result;
    }

    //根据编号来获取当前的课程信息
    @RequestMapping("currentOneCourse")
    @ResponseBody
    public Map<String,Object> currentOneCourse(Integer courseId){
        CourseInfo courseInfos = courseService.currentOneCourse(courseId);
        Map<String,Object> result = new HashMap<>();
        result.put("code",0);
        result.put("courses",courseInfos);
        System.out.println(result);
        return result;
    }

    //编辑修改后的数据
    @RequestMapping("editOneCourse")
    @ResponseBody
    public Map<String,Object> editOneCourse(CourseInfo courseInfo){
        Integer i = courseService.editOneCourse(courseInfo);
        System.out.println(i+"------------------------------");
        Map<String,Object> result = new HashMap<>();
        result.put("code",0);
        result.put("course",i);
        return result;

    }

    //分页操作功能
    @RequestMapping("pageCourse")
    @ResponseBody
    public Map<String,Object> pageCourse(Integer currentPage,Integer pageSize){

        PageInfo<CourseInfo> pageInfo = courseService.pageCourse(currentPage,pageSize);

        Map<String,Object> result = new HashMap<>();
        result.put("code",0);
        result.put("message","获取用户数据成功");
        result.put("courseList",pageInfo.getList());//返回查询出来的分页数据
        result.put("totalPage",pageInfo.getPages());//返回当前总共有多少页
        return result;
    }



}
